import { createStore } from "vuex";
import { login, getPermissions, importExcel,getlist } from "../Api/request";

export default createStore({
  state: {
    token: "",
  },
  getters: {
    token(state) {
      return state.token;
    },
  },
  mutations: {
    token(state, token) {
      state.token = token;
      localStorage.setItem("token", token);
    },
  },
  actions: {
    // 请求登陆接口
    login({ commit }, obj) {
      return new Promise((reslove) => {
        login(obj).then((res) => {
          if (res.success) {
            reslove(res);
            commit("token", "Bearer " + res.data.token);
          }
        });
      });
    },
    // 请求员工列表数据
    getPermissionsList(a, obj) {
      return new Promise((reslove) => {
        getPermissions(obj).then((res) => {
          reslove(res);
        });
      });
    },
    // 将excel文件提取成数组添加到接口中
    excelImport(a, obj) {
      return new Promise((reslove) => {
        importExcel(obj).then((res) => {
          reslove(res);
        });
      });
    },
    // 获取所有员工列表
    getAllList(){
      return new Promise(reslove=>{
        getlist().then(res=>{
          reslove(res);
        })
      })
    }
  },
  modules: {},
});
